
 $(document).ready(function() {
 	var cookie=  $.AMUI.utils.cookie;
 	var sessionId=(cookie.get("sessionId")==null)?"":cookie.get("sessionId");
 	var factoryId=(cookie.get("factoryid")==null)?"":cookie.get("factoryid");
	$.getJSON ("json/locat.json", function (data) {
		var locat=data["url"];
		var  factoryid=data["factoryid"];
				if(factoryId != factoryid)
					window.location.href="login.html";
		 $.ajax(locat+"/clientUser/savedriver1?sessionId="+sessionId, {
	            type: "GET",
	            xhrFields: {
	                withCredentials: true,
	                useDefaultXhrHeader: false
	            },
	            crossDomain: true,
	            success: function(data, status, xhr) {
	            	if(data["msg"]=="error"){
	            		window.location.href="login.html";
	            	}
	            },
				error:function(data){
					swal("","服务异常！","error");
					window.location.href=login.html;
	            }
	        });
		
	});
 	
 	
 });



//保存司机
function save(){
	var cookie=  $.AMUI.utils.cookie;
 	var sessionId=(cookie.get("sessionId")==null)?"":cookie.get("sessionId");
	var drivername = $("#drivername").val();
	var driverphone = $("#driverphone").val();
	var tracknumber = $("#tracknumber").val();
	if(drivername==""||driverphone==""||tracknumber==""){
			$("#doc-vld-msg").submit();
			return false;
	}else{
		if(driverphone.length!=11||tracknumber.length!=7){
			$("#doc-vld-msg").submit();
			return false;
		}else{
			var id = "body-loading";
  	$(window).loading({action:"open",id:id,font:40}); 
	$.getJSON ("json/locat.json", function (data) {
			var  locat=data["url"];
			var factoryid=data["factoryid"];
	        $.ajax(locat+"/clientUser/saveDriver?sessionId="+sessionId, {
	            type: "POST",
	            xhrFields: {
	                withCredentials: true,
	                useDefaultXhrHeader: false
	            },
	            data: {
	                drivername: drivername,
	                driverphone: driverphone,
	                tracknumber: tracknumber
	            },
	            crossDomain: true,
	            success: function(data, status, xhr) {
	            		var time = setTimeout(function(){
			   				//关闭
			   				$(window).loading({action:"close",id:id});
			   			},100);
						if("success" == data["msg"]){
								swal("Good","新增成功","success");
								window.location.href="tjsj.html";
						}
	            },
	            error:function(data){
	            	var time = setTimeout(function(){
			   				//关闭
			   				$(window).loading({action:"close",id:id});
			   			},100);
	            	swal("","服务异常！","error");
	            	window.location.href=login.html;
	            }
	        });
    });  
		}
		
	}
	



}
